package com.xingkeduo.pojo.json;


import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.xingkeduo.pojo.query.ShopsDaysQuery;
import com.xingkeduo.pojo.table.ShopsDaysTable;
import com.xingkeduo.util.pojo.base.BaseJson;
import com.xingkeduo.util.pojo.enums.YesNoEnum;
import com.xingkeduo.util.pojo.exception.InputParamException;

import java.text.DateFormat;

public class ShopsDaysJson extends BaseJson {

	public static ShopsDaysQuery createQueryForShopsDays(String json) throws Throwable {
		ShopsDaysQuery query = new ShopsDaysQuery();
		JsonNode root = validJson(json);
		if (root == null)
			return query;
		query.setCode(validCode(root, YesNoEnum.YES));
		return query;
	}

	public static ObjectNode toJson(ShopsDaysTable shopsDays) {
		ObjectNode root = MAPPER.createObjectNode();

		if (shopsDays != null)
		{
			root.put("id", shopsDays.getId());
			root.put("code", shopsDays.getCode());
			root.put("shopsId", shopsDays.getShopsId());
			root.put("dayids", shopsDays.getDayids());
			root.put("starttime", shopsDays.getStarttime());
			root.put("endtime", shopsDays.getEndtime());
			//处理时间
/*			String createdTime = DateFormat.getDateTimeInstance().format(shopsDays.getCreatedTime());//可以精确到时分秒
			root.put("createdtime", createdTime);*/
		}

		return root;
	}

	public static ShopsDaysTable createTableForModifyShopsDays(String urlParam, ShopsDaysTable shopsDays) throws Throwable {
		JsonNode root = validJson(urlParam);
		if (root == null)
			throw new InputParamException(InputParamException.Type.INVALID, "参数");

		shopsDays.setCode(validCode(root, YesNoEnum.YES));

		return shopsDays;
	}


}
